package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceDataTempAddDTO;
import org.jsola.hr.dto.AttendanceDataTempUpdateDTO;
import org.jsola.hr.entity.AttendanceDataTempDO;
import org.jsola.hr.query.AttendanceDataTempQuery;
import org.jsola.hr.service.IAttendanceDataTempService;
import org.jsola.hr.vo.AttendanceDataTempVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 临时考勤数据
 *
 * @author zhr
 */
@Component
public class AttendanceDataTempTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceDataTempService attendanceDataTempService;

    /**
     * 生成add测试数据
     * @return AttendanceDataTempAddDTO
     */
    public AttendanceDataTempAddDTO getAttendanceDataTempAddDTO(){
        AttendanceDataTempAddDTO attendanceDataTempAddDTO = new AttendanceDataTempAddDTO();
        attendanceDataTempAddDTO.setWorkingHours(getRandomValue("varchar",200));
        attendanceDataTempAddDTO.setErrorCol(getRandomValue("varchar",200));
        attendanceDataTempAddDTO.setAttendanceDataRecordId(getRandomValue("varchar",32));
        attendanceDataTempAddDTO.setValue(getRandomValue("varchar",3000));
        attendanceDataTempAddDTO.setIsError(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendanceDataTempAddDTO.setIsHandle(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendanceDataTempAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        attendanceDataTempAddDTO.setEmpId(getRandomValue("varchar",32));
        attendanceDataTempAddDTO.setEmpName(getRandomValue("varchar",32));
        attendanceDataTempAddDTO.setEmpPhone(getRandomValue("varchar",32));
        attendanceDataTempAddDTO.setYear(SafeKit.getInteger(getRandomValue("int",10)));
        attendanceDataTempAddDTO.setMonth(SafeKit.getInteger(getRandomValue("int",10)));
        attendanceDataTempAddDTO.setSallaryImpact(SafeKit.getBigDecimal(getRandomValue("decimal",12)));
        attendanceDataTempAddDTO.setErrorReason(getRandomValue("varchar",32));
        return attendanceDataTempAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceDataTempUpdateDTO
     */
    public AttendanceDataTempUpdateDTO getAttendanceDataTempUpdateDTO(AttendanceDataTempVO attendanceDataTempVO){
        return attendanceDataTempService.selectDOById(attendanceDataTempVO.getId(), SITE_ID).to(AttendanceDataTempUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceDataTempQuery
     */
    public AttendanceDataTempQuery getAttendanceDataTempQuery() {
        AttendanceDataTempQuery attendanceDataTempQuery = new AttendanceDataTempQuery();
        List<AttendanceDataTempDO> attendanceDataTempDOList = attendanceDataTempService.list(new AttendanceDataTempDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceDataTempDOList)) {
            AttendanceDataTempDO attendanceDataTempDO = attendanceDataTempDOList.get(0);
            attendanceDataTempQuery = attendanceDataTempDO.to(AttendanceDataTempQuery.class);
        }
        return attendanceDataTempQuery;
    }

    /**
     * 保存示例
     * @return AttendanceDataTempVO
     */
    public AttendanceDataTempVO saveAttendanceDataTempExample(){
        AttendanceDataTempAddDTO addDTO = this.getAttendanceDataTempAddDTO();
        AttendanceDataTempVO attendanceDataTempVO = attendanceDataTempService.save(addDTO,buildTokenUser());
        return attendanceDataTempVO;
    }


}

